<template>
  <div class="wrapper">
    <div class="wrapper__left">
      <div class="left_header">
        <div class="logo"></div>
        <div class="title">Admin</div>
      </div>
      <!-- 菜单 -->
      <el-menu
        class="el-menu-vertical-demo menu"
        background-color="#031524"
        text-color="#fff"
        active-text-color="#409EFF"
        router="true"
      >
        <tree-menu :userMenu="userMenu" />
      </el-menu>
      <!-- /菜单结束 -->
    </div>
    <div class="wrapper__right">
      <header class="main__header">
        <div class="main__header__left">
          <i class="iconfont">&#xe655;</i>
          <Breadcrumbs />
        </div>
        <div class="main__header__right">
          <el-badge
            :is-dot="notifyCount > 0 ? true : false"
            type="danger"
            class="icon-info iconfont"
            @click="$router.push('/audit/approve')"
            >&#xe632;</el-badge
          >
          <el-dropdown>
            <span class="el-dropdown-link">
              {{ userinfo.userName || "未登录" }}
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item icon="el-icon-s-promotion" @click="logoQuit"
                  >退出</el-dropdown-item
                >
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </header>
      <div class="main">
        <div class="main__content">
          <router-view></router-view>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import TreeMenu from "./TreeMenu.vue";
import Breadcrumbs from './Breadcrumbs.vue'
export default {
  components: { TreeMenu, Breadcrumbs },
  data () {
    return {
      userinfo: this.$store.state.userInfo,
      notifyCount: 0,
      userMenu: [],
    }
  },
  computed: {
    notifyCount () {
      return this.$store.state.notifyCount
    }
  },
  mounted () {
    this.getNotify()
    this.getMenuList()
  },
  methods: {
    async getNotify () {
      const count = await this.$api.getNotify()
      this.$store.commit('savenotifyCount', count)
    },
    logoQuit () {
      this.$store.commit('saveUserInfo', '')
      this.$router.push('/login')
    },
    async getMenuList () {
      const { menuList, actionList } = await this.$api.getPermissionList()
      this.userMenu = menuList
      this.$store.commit('saveUserMenu', menuList)
      this.$store.commit('saveUserAction', actionList)
    }
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 100vw;
  height: 100vh;
  position: relative;
  &__left {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 3rem;
    overflow: hidden;
  }
  &__right {
    position: fixed;
    left: 3rem;
    right: 0;
    top: 0;
    bottom: 0;
    background: #ebeef1;
  }
}
.main {
  padding: 20px;
  &__header {
    display: flex;
    justify-content: space-between;
    background: #fff;
    height: 0.5rem;
    border-bottom: 0.01rem solid #ccc;
    align-items: center;
    padding: 0 0.2rem;
    .icon-info {
      margin-right: 0.1rem;
      cursor: pointer;
    }
    .user__name {
      cursor: pointer;
    }
  }
  &__content {
    background: #ebeef1;
    height: 90vh;
  }
}

.menu {
  height: 100%;
  border: none;
}

.main__header__left {
  display: flex;
  .iconfont {
    margin-right: 0.2rem;
  }
}

.left_header {
  height: 0.5rem;
  background: #031524;
  display: flex;
  width: 100%;
  padding: 0 0.2rem;
  .logo {
    background: url("./../assets/logo.png") no-repeat;
    background-size: 0.5rem 0.5rem;
    width: 0.5rem;
  }
  .title {
    color: #fff;
    text-align: center;
    line-height: 0.5rem;
    font-weight: bold;
    font-size: 0.3rem;
    padding-left: 0.2rem;
  }
}
</style>